package com.ggqq.day317;

import java.util.Arrays;

public class XuanZhuan {
    public static void main(String[] args){
        int[] num = {3,1,1};
        XuanZhuan xuanZhuan = new XuanZhuan();
        System.out.println(xuanZhuan.minArray(num));

    }
    public int minArray(int[] numbers){
        //方法一：暴力
//        Arrays.sort(numbers);
//        return  numbers[0];
        //方法二：二分查找
        int left = 0;
        int right = numbers.length-1;
        while(left<right){
            int mid = (left+right)/2;
            if(numbers[mid]>numbers[right]){
                left=mid+1;
            }else if(numbers[mid]<numbers[right]){
                right=mid;
            }else{
                right--;//相等的情况下，缩小范围
            }
        }
        return numbers[left];
    }
}
